package com.example.nkj.progressbar;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.SeekBar;
import android.widget.ProgressBar;
import android.widget.TextView;

public class progressbar extends AppCompatActivity
{
    private SeekBar seekbar1;
    private SeekBar seekbar2;
    private ProgressBar progressbar1;
    private ProgressBar progressbar2;
    private TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_progressbar);

        textView = (TextView) findViewById(R.id.textView);
        seekbar1 = (SeekBar) findViewById(R.id.seekBar);
        seekbar2 = (SeekBar) findViewById(R.id.seekBar2);
        progressbar1 = (ProgressBar) findViewById(R.id.progressBar);
        progressbar2 = (ProgressBar) findViewById(R.id.progressBar2);
        seekbar1.setMax(100);//maxAmount为最大额度
        seekbar2.setMax(10);//maxAmount为最大额度

        seekbar1.setOnSeekBarChangeListener(sbl);
        seekbar2.setOnSeekBarChangeListener(sbl);
    };
    /*
     * onProgressChanged：进度条改变事件
     * onStartTrackingTouch：进度条开始拖动事件
     * onStopTrackingTouch：进度条停止拖动事件
     * @see android.widget.SeekBar.OnSeekBarChangeListener
     */
    private SeekBar.OnSeekBarChangeListener sbl = new SeekBar.OnSeekBarChangeListener()
    {
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
        {
            if(seekBar.getId() == R.id.seekBar)
            {
                progressbar1.setProgress(progress);
                textView.setText("seekbar1 " + String.valueOf(progress) + "%");
            }
            else if (seekBar.getId() == R.id.seekBar2)
            {
                progressbar2.setProgress(progress);
                textView.setText("seekbar2 " + String.valueOf(progress) + "/10");
            }
        }

        public void onStartTrackingTouch(SeekBar seekBar)
        {
            textView.setText("start seekbar");
        }

        public void onStopTrackingTouch(SeekBar seekBar)
        {
            textView.setText("stop seek bar");
        }
    };

}
